﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMP.ERP.Admin.ServiceReference1;

namespace CMP.ERP.Admin.Controllers
{
    public class ExperssController : Controller
    {
        //
        // GET: /Experss/
        ServiceReference1.Service1Client client = new Service1Client();
        /// <summary>
        /// 显示供应商
        /// </summary>
        /// <returns></returns>
        public ActionResult Experss_Show()
        {
            ViewBag.CityID = new SelectList(client.ShowCity().ToList(), "CityID", "CityName");
            List<ServiceReference1.ProviderInfo> list = new List<ProviderInfo>();
            list = client.ProviderInfoShow().ToList();
            return View(list);
        }
        /// <summary>
        /// 添加供应商信息
        /// </summary>
        /// <param name="Provd"></param>
        /// <returns></returns>
        public string Experss_Add(ProviderInfo Provd)
        {
            if (client.ProviderInfoAdd(Provd) > 0)
            {
                string str="添加成功";
                string url="/Experss/Experss_Show";
                return Caution.GetJavaScriptUrl(str,url);
                //return Content("<script>alert('添加成功');location.href='/Experss/Experss_Show'</script>");
            }
            else
            {
                string str = "添加失败";
                string url = "/Experss/Experss_Show";
                return Caution.GetJavaScriptUrl(str, url);
                //return Content("<script>alert('添加失败');location.href='/Experss/Experss_Show'</script>");
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Experss_Delete(int id)
        {
            if (client.ProviderInfoDelete(id) > 0)
            {
                return Content("<script>alert('删除成功');location.href='/Experss/Experss_Show'</script>");
            }
            else
            {
                return Content("<script>alert('删除失败');location.href='/Experss/Experss_Show'</script>");
            }
        }
        /// <summary>
        /// 修改页面
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Experss_Update(int id)
        {
            ViewBag.CityID = new SelectList(client.ShowCity().ToList(), "CityID", "CityName");
            return View(client.ProviderInfoGetID(id));
        }
        /// <summary>
        /// 修改功能
        /// </summary>
        /// <param name="pro"></param>
        /// <returns></returns>
        public ActionResult Experss_ProUpdate(ProviderInfo pro)
        {
            if (client.ProviderInfoUpdate(pro) > 0)
            {
                return Content("<script>alert('修改成功');location.href='/Experss/Experss_Show'</script>");
            }
            else
            {
                return Content("<script>alert('修改失败');location.href='/Experss/Experss_Show'</script>");
            }
        }
        /// <summary>
        /// 搜索
        /// </summary>
        /// <param name="ProName"></param>
        /// <returns></returns>
        public ActionResult Experss_Select(string ProName)
        {
            ViewBag.CityID = new SelectList(client.ShowCity().ToList(), "CityID", "CityName");
            List<ServiceReference1.ProviderInfo> list = new List<ProviderInfo>();
            list = client.ProviderInfoSelect(ProName).ToList();
            return View("Experss_Show",list);
        }
    }
}
